﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Security.Cryptography;
using System.Text;

public class Security
{

    private static Security instance;
    private String salt;

	private Security()
	{
        salt = "stegtflæsk";
	}

    public static Security getInstance()
    {
        if (instance == null)
        {
            instance = new Security();
        }
        return instance;
    }

    public String encryptString(String unEncrypted)
    {
        var hmacSHA1 = new HMACSHA1(Encoding.UTF8.GetBytes(salt));
        var saltedHash = hmacSHA1.ComputeHash(Encoding.UTF8.GetBytes(unEncrypted));

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < saltedHash.Length; i++)
        {
            stringBuilder.Append(saltedHash[i].ToString("x2"));
        }

        return stringBuilder.ToString();
    }
}
